Skip to content

identity brain tab refresh fix#2139

Merged
simo6529 merged 3 commits intomainfrom
identity-brain-tab-refresh-fix
Mar 19, 2026
Merged

identity brain tab refresh fix#2139
simo6529 merged 3 commits intomainfrom
identity-brain-tab-refresh-fix

Conversation

@simo6529
Copy link
Copy Markdown
Collaborator

@simo6529 simo6529 commented Mar 19, 2026

Summary by CodeRabbit

Bug Fixes

  • Fixed unexpected page redirects that occurred while wallet connections were initializing or profile data was loading, ensuring users remain on the Brain tab during these loading states.
  • Improved stability when accessing brain features by preventing premature navigation away from the page during critical initialization phases.

Signed-off-by: Simo <simo@6529.io>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 19, 2026

📝 Walkthrough

Walkthrough

This PR refactors redirect suppression logic in the user page brain functionality. It removes client-side redirect logic from UserPageBrainWrapper and consolidates redirect management into UserPageTabs using a new utility function. The logic now evaluates wallet connection state, client hydration status, and profile loading to determine whether to suppress brain tab redirects.

Changes

Cohort / File(s) Summary
UserPageBrainWrapper Component
components/user/brain/UserPageBrainWrapper.tsx
Removed client-side redirect logic using useRouter and useEffect, eliminated dependencies on useSeizeConnectContext and unused context values (connectedProfile, activeProfileProxy). Now provides fallback profile when useIdentity returns null.
UserPageBrainWrapper Tests
__tests__/components/user/brain/UserPageBrainWrapper.test.tsx
Extended mocks for useSeizeConnectContext (added connectionState) and useIdentity (added hydratedIdentity). Updated UserPageDrops mock for deterministic rendering. Replaced test cases to verify placeholder display, drops rendering, and hydration-pending states.
UserPageTabs Component
components/user/layout/UserPageTabs.tsx
Integrated useSeizeConnectContext for wallet state, added isClientHydrated flag via useSyncExternalStore, and imported redirect suppression utility. Brain redirect now suppressed when shouldDelayUserPageBrainRedirect returns true; brain tab remains visible during suppression.
UserPageTabs Tests
__tests__/components/user/layout/UserPageTabs.test.tsx
Added useSeizeConnectContext mock with controllable address and connectionState. Updated UserPageTab mock to expose active state via data-active. Added comprehensive test cases for brain tab behavior during wallet state transitions, profile loading, and waves availability.
Redirect Suppression Logic
components/user/layout/userPageBrainAccess.ts
New utility module exporting shouldDelayUserPageBrainRedirect function that evaluates redirect suppression based on client hydration, wallet connection state (initializing/connecting), and profile fetch status.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • ragnep
  • prxt6529

Poem

🐰 A rabbit hops through redirect mazes,
Clearing useRouter from the brain's traces,
Now hydration checks and connection states,
Keep tabs alive at loading's gates—
Logic flows cleaner, tests shine bright,
Brain tabs persist through the hydration night! 🌙

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'identity brain tab refresh fix' is concise and directly related to the main change: refactoring brain tab redirect logic to handle wallet connection states and profile hydration more robustly.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch identity-brain-tab-refresh-fix
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
__tests__/components/user/layout/UserPageTabs.test.tsx (1)

182-290: The hydration-specific guard still isn't pinned directly.

These cases cover wallet and profile-loading transitions, but the dedicated !isClientHydrated branch in shouldDelayUserPageBrainRedirect is still untested. A tiny unit suite around the helper would lock down the refresh regression more directly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@__tests__/components/user/layout/UserPageTabs.test.tsx` around lines 182 -
290, The tests exercise wallet/profile transitions but miss the hydration-only
branch; add a focused unit test for the helper shouldDelayUserPageBrainRedirect
that pins the !isClientHydrated case by calling the function (or importing it)
with isClientHydrated=false and relevant params (e.g., pathname "/:user/brain",
connectionState values, fetchingProfile false/true) and assert it returns true
so the redirect is delayed; place the test near UserPageTabs.test.tsx (or create
a small helper test file) and mock any dependencies used by
shouldDelayUserPageBrainRedirect to ensure the branch is deterministically hit.
__tests__/components/user/brain/UserPageBrainWrapper.test.tsx (1)

71-86: This case now duplicates the first placeholder test.

Once showWaves is false, UserPageBrainWrapper no longer consults address, connectionState, or hydratedIdentity, so this exercises the same branch as the earlier "brain stays unavailable" case. I'd either drop it or repurpose it into a positive assertion around the profile ?? initialProfile fallback.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@__tests__/components/user/brain/UserPageBrainWrapper.test.tsx` around lines
71 - 86, The test "keeps the placeholder while hydration is still pending"
duplicates the earlier "brain stays unavailable" branch because showWaves: false
makes UserPageBrainWrapper ignore address/connectionState/hydratedIdentity;
either delete this test or change it to assert the positive fallback behavior:
render with showWaves: false and verify the component uses profile ??
initialProfile (e.g., check that the initialProfile content is present) instead
of asserting the placeholder; locate the test by its description and
update/remove it accordingly (references: UserPageBrainWrapper, showWaves,
profile ?? initialProfile).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@__tests__/components/user/brain/UserPageBrainWrapper.test.tsx`:
- Around line 71-86: The test "keeps the placeholder while hydration is still
pending" duplicates the earlier "brain stays unavailable" branch because
showWaves: false makes UserPageBrainWrapper ignore
address/connectionState/hydratedIdentity; either delete this test or change it
to assert the positive fallback behavior: render with showWaves: false and
verify the component uses profile ?? initialProfile (e.g., check that the
initialProfile content is present) instead of asserting the placeholder; locate
the test by its description and update/remove it accordingly (references:
UserPageBrainWrapper, showWaves, profile ?? initialProfile).

In `@__tests__/components/user/layout/UserPageTabs.test.tsx`:
- Around line 182-290: The tests exercise wallet/profile transitions but miss
the hydration-only branch; add a focused unit test for the helper
shouldDelayUserPageBrainRedirect that pins the !isClientHydrated case by calling
the function (or importing it) with isClientHydrated=false and relevant params
(e.g., pathname "/:user/brain", connectionState values, fetchingProfile
false/true) and assert it returns true so the redirect is delayed; place the
test near UserPageTabs.test.tsx (or create a small helper test file) and mock
any dependencies used by shouldDelayUserPageBrainRedirect to ensure the branch
is deterministically hit.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bc2276fa-a191-4631-b4a7-2898e4c96033

📥 Commits

Reviewing files that changed from the base of the PR and between c7171f7 and 198e078.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • __tests__/components/user/brain/UserPageBrainWrapper.test.tsx
  • __tests__/components/user/layout/UserPageTabs.test.tsx
  • components/user/brain/UserPageBrainWrapper.tsx
  • components/user/layout/UserPageTabs.tsx
  • components/user/layout/userPageBrainAccess.ts

@simo6529 simo6529 merged commit bfaae1f into main Mar 19, 2026
6 checks passed
@simo6529 simo6529 deleted the identity-brain-tab-refresh-fix branch March 19, 2026 14:01
@sonarqubecloud
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot mentioned this pull request Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants